﻿package com.crayon.ui
{
	import flash.display.InteractiveObject;
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	/**
	 * ...
	 * @author 蜡笔
	 * 
	 * usage:
	 * var myMenuContext:CopyrightMenu = new CopyrightMenu(this,"蜡笔工作室",true,"http://hi.baidu.com/蜡笔工作室");
	 */
	public class CopyrightMenu
	{
		private var myContextMenu:ContextMenu;
		private var menuItem:ContextMenuItem;
		
		private var target:InteractiveObject;
		private var str:String;
		private var url:String;
		private var isURL:Boolean;
		
		public function CopyrightMenu(target:InteractiveObject, str:String = "", isURL:Boolean = false, url:String="" ) 
		{
			this.target = target;
			this.str = str;
			this.isURL = isURL;
			this.url = url;
			
			addNewItem();
		}
		
		public function addNewItem():void {
			myContextMenu = new ContextMenu();
			//隐藏默认右键其他选项
			myContextMenu.hideBuiltInItems();
			
			menuItem = new ContextMenuItem(this.str);
			myContextMenu.customItems.push(menuItem);
			target.contextMenu = myContextMenu;
			menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelect);
		}
		private function itemSelect(evt:ContextMenuEvent):void {
			//do something
			isURL?navigateToURL(new URLRequest(url)):trace(url);
		}
	}

}



/*
var mymenu:ContextMenu = new ContextMenu();
var myitem0:ContextMenuItem = new ContextMenuItem("- 使用说明 -");
var myitem1:ContextMenuItem = new ContextMenuItem("访问官方网站");
var myitem2:ContextMenuItem = new ContextMenuItem("蜡笔制作");
mymenu.customItems.push(myitem0);
mymenu.customItems.push(myitem1);
mymenu.customItems.push(myitem2);
mymenu.hideBuiltInItems();
this.contextMenu = mymenu; 
myitem0.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,help);
myitem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,gotoseti1);
myitem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,gotoseti2);
function help(event:ContextMenuEvent):void {
    var url:URLRequest = new URLRequest("http://hi.baidu.com/蜡笔工作室");
    navigateToURL(url);
}
function gotoseti1(event:ContextMenuEvent):void{
        var url:URLRequest = new URLRequest("http://hi.baidu.com/蜡笔工作室");
        navigateToURL(url);
}
function gotoseti2(event:ContextMenuEvent):void{
        var url:URLRequest = new URLRequest("http://hi.baidu.com/蜡笔工作室");
        navigateToURL(url);
}
*/